<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Responsive Image Carousel</title>
<style>
  * {
    box-sizing: border-box;
  }
  body {
    font-family: Arial, sans-serif;
    margin: 0;
    padding: 0;
  }
  .carousel {
    position: relative;
    width: 100%;
    max-width: 800px;
    margin: 0 auto;
    overflow: hidden;
  }
  .carousel-container {
    display: flex;
    transition: transform 0.5s ease-in-out;
    position: relative;
    width: 100%;
  }
  .carousel-item {
    flex: 0 0 100%;
  }
  .carousel-item img {
    max-width: 100%;
    height: auto;
    display: block;
    cursor: pointer;
    transition: transform 0.3s ease;
  }
  .carousel-item img:active {
    transform: scale(0.98);
    outline: none;
    box-shadow: none;
  }
  .carousel-control {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 50px;
    height: 50px;
    background-color: transparent;
    color: white;
    font-size: 24px;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    transition: color 0.3s ease;
    opacity: 0.7;
    border: none;
    outline: none;
    box-shadow: none;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
  }
  .carousel-control.prev {
    left: 10px;
  }
  .carousel-control.next {
    right: 10px;
  }
  .carousel-control.prev:focus,
  .carousel-control.next:focus {
    outline: none;
  }
  .carousel-control:active {
    background-color: transparent;
  }
  .carousel-indicators {
    position: absolute;
    bottom: 10px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 10;
  }
  .carousel-indicator {
    width: 10px;
    height: 10px;
    background-color: rgba(255, 255, 255, 0.5);
    border-radius: 50%;
    margin: 0 5px;
    cursor: pointer;
    transition: background-color 0.3s ease;
    box-shadow: none;
    -webkit-tap-highlight-color: transparent;
  }
  .carousel-indicator.active {
    background-color: white;
  }
  .carousel-indicator:focus {
    outline: none;
  }
  .carousel-indicator:active {
    background-color: rgba(255, 255, 255, 0.5);
  }
</style>
</head>
<body>
<div class="carousel">
  <div class="carousel-container" id="carouselContainer">
    <!-- Carousel items will be dynamically added here -->
  </div>
  <div class="carousel-control prev" id="prevBtn">&lt;</div>
  <div class="carousel-control next" id="nextBtn">&gt;</div>
  <div class="carousel-indicators" id="carouselIndicators">
    <!-- Carousel indicators will be dynamically added here -->
  </div>
</div>

<script>
  document.addEventListener('DOMContentLoaded', function() {
    eval(fy_bridge_app.getInternalJs());
    const ruleMap = JSON.parse(fba.getVar(":ruleMap"));
    const images = JSON.parse(fba.getVar(":carouselMap"));

    const carouselContainer = document.getElementById('carouselContainer');
    const prevBtn = document.getElementById('prevBtn');
    const nextBtn = document.getElementById('nextBtn');
    const carouselIndicators = document.getElementById('carouselIndicators');

    let currentIndex = 0;

    function showImage(index) {
      currentIndex = index;
      carouselContainer.style.transform = `translateX(-${index * 100}%)`;

      const indicators = document.querySelectorAll('.carousel-indicator');
      indicators.forEach((indicator, i) => {
        if (i === index) {
          indicator.classList.add('active');
        } else {
          indicator.classList.remove('active');
        }
      });
    }

    images.forEach((image, index) => {
      const item = document.createElement('div');
      item.classList.add('carousel-item');

      const imageElement = document.createElement('img');
      imageElement.src = image.pic;
      imageElement.alt = 'slide';
      item.appendChild(imageElement);
      carouselContainer.appendChild(item);

      if (image.url && !image.url.startsWith("http") && !image.url.startsWith("https")) {
        imageElement.addEventListener('click', () => {
          fba.open(JSON.stringify({
              rule: ruleMap.title,
              url: `hiker://page/Carousel.view?rule=酷安&page=fypage&array=${encodeURIComponent(JSON.stringify(image))}&hiker=#noHistory##noRecordHistory##gameTheme#fypage`,
              findRule: ruleMap.detail_find_rule,
              extra: {
                      newWindow: true,
                      windowId: ruleMap.title,
                      pageTitle: image.title
              }
          }));
        });
      }

      const indicator = document.createElement('div');
      indicator.classList.add('carousel-indicator');
      if (index === 0) {
        indicator.classList.add('active');
      }
      carouselIndicators.appendChild(indicator);

      indicator.addEventListener('click', () => {
        showImage(index);
      });
    });

    function nextImage() {
      currentIndex++;
      if (currentIndex === images.length) {
        currentIndex = 0;
      }
      showImage(currentIndex);
    }

    function prevImage() {
      currentIndex--;
      if (currentIndex < 0) {
        currentIndex = images.length - 1;
      }
      showImage(currentIndex);
    }

    nextBtn.addEventListener('click', nextImage);
    prevBtn.addEventListener('click', prevImage);

    setInterval(nextImage, 3000);

  });
</script>

</body>
</html>